<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\admin\model\Song as SongModel;
use think\Db;

/**
 * @歌曲接口
 */
class Song extends Api
{    
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['list', 'info'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    
    /**
     * @歌曲列表
     */
    public function list(SongModel $D, $column_id = null, $flag = null, $type = null, $ctype = null, $orderBy='id', $orderType='DESC', $page=1, $pageSize=10)
    {
        $map = [];
        if ($column_id) {
            $map['column_id'] = $column_id;
        }
        if ($flag) {
            $map[] = ['exp',Db::raw("FIND_IN_SET('{$flag}',flag)")];
        }
        if ($type) {
            if ($type == 'hot') {
                $map[] = ['exp',Db::raw("FIND_IN_SET('{$type}',flag)")];
            } else {
                if ($type == 'new') {
                    $orderType = 'DESC';
                } elseif ($type == 'return') {
                    $orderBy   = 'returntime';
                    $orderType = 'DESC';
                }
            }
        } elseif ($ctype){            
            $orderBy   = $ctype.'_num';  
            $orderType = 'DESC';
        }
        
        $list = $D->where($map)
                  ->order($orderBy, $orderType)
                  ->paginate($pageSize);
        
        $this->success('歌曲列表', $list);
    }
    
    
    /**
     * @歌曲详情
     */
    public function info(SongModel $D, $id = null)
    {
        if (!$id) {
            $this->error('歌曲id不能为空');
        }        
        $info = $D->get($id);
              
        $this->success('歌曲详情', $info);
    }    
    
}
